package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.BuyBean;
import com.project.bean.BuyInfoBean;
import com.project.mapper.IBuyMapper;
import com.project.service.IBuyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

@Service
public class BuyServiceImpl implements IBuyService {
    @Autowired
    private IBuyMapper buyMapper;

    @Override
    public IPage<BuyBean> cutFindByItem(Integer pageNum, String supplierName,
                                            LocalDate startDate, LocalDate endDate) {
        QueryWrapper<BuyBean> qw = new QueryWrapper<>();
        if (supplierName != null && !supplierName.equals("")){
            qw.like("b_supplierName",supplierName);
        }
        if (startDate != null){
            qw.ge("b_createDate",startDate);
        }
        if (endDate != null){
            qw.le("b_createDate",endDate);
        }
        return buyMapper.selectPage(new Page<>(pageNum,1),qw);
    }

    @Override
    public void add(BuyBean buyBean) {
        buyMapper.insert(buyBean);
    }

    @Override
    public BuyBean findById(Integer buyId) {
        return buyMapper.findById(buyId);
    }
}
